package com.wing.sell.service.impl;

import cn.hutool.core.bean.BeanUtil;
import cn.hutool.core.bean.copier.CopyOptions;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.wing.sell.dao.CustomerFollowRecordDao;
import com.wing.sell.model.entity.CustomerFollowRecord;
import com.wing.sell.model.request.CustomerFollowRecordForm;
import com.wing.sell.model.response.CustomerFollowRecordVO;
import com.wing.sell.service.CustomerFollowRecordService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;
import java.util.Map;

/**
 * 跟进记录管理-ServiceImpl
 *
 * @author
 */
@Service
@Slf4j
public class CustomerFollowRecordServiceImpl extends ServiceImpl<CustomerFollowRecordDao, CustomerFollowRecord> implements CustomerFollowRecordService {

    @Override
    @Transactional
    public int add(CustomerFollowRecordForm customerFollowRecordForm) {

        int repetition = 0001;//重复数据
        int success = 0002;//添加成功
        int fail = 0003;//添加失败

        //校验
        CustomerFollowRecord customerFollowRecord =new CustomerFollowRecord();
        CopyOptions copyOptions = CopyOptions.create()
        .setEditable(CustomerFollowRecord.class)
        .setIgnoreError(true)
        .setIgnoreNullValue(true);
        BeanUtil.copyProperties(customerFollowRecordForm, customerFollowRecord, copyOptions);

        if (baseMapper.insert(customerFollowRecord)>0){
            return success;
        }
        return fail;
    }

    @Override
    public List<CustomerFollowRecordVO> list4app(Map<String, Object> params) {
        return baseMapper.list4app(params);
    }

    @Override
    public Page<CustomerFollowRecordVO> pageList4app(Page page, Map<String, Object> params) {
        List<CustomerFollowRecordVO> list = baseMapper.list4app(page, params);
        page.setRecords(list);
        return page;
    }

    @Override
    public CustomerFollowRecordVO get4appById(Long id) {
        return baseMapper.get4appById(id);
    }
}
